###############################################################################
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON)

PROJECT(vw)

###############################################################################
IF(CMAKE_SIZEOF_VOID_P MATCHES 8)
    MESSAGE(STATUS "Detected 64-bit platform.")
    SET(PLATFORM_X64 TRUE)
    ADD_DEFINITIONS(-D__64BIT__)
ELSE()
    MESSAGE(STATUS "Detected 32-bit platform.")
ENDIF()

IF (WIN32)
    ADD_DEFINITIONS(-D__WINDOWS__)
    ADD_DEFINITIONS(-D_WIN32_WINNT=0x0501)
    ADD_DEFINITIONS(-W3)
    ADD_DEFINITIONS(-D__DLL__)
ELSE ()
    ADD_DEFINITIONS(-D__LINUX__)
    ADD_DEFINITIONS(-Wall)
    IF (CMAKE_COMPILER_IS_GNUCXX)
        ADD_DEFINITIONS(-std=gnu++0x)
    ELSE ()
        ADD_DEFINITIONS(-std=stdc++11)
    ENDIF()
ENDIF()

option(DEBUG "DEBUG" FALSE)
IF (DEBUG)
    ADD_DEFINITIONS(-D__DEBUG__)
ENDIF()

## find library ###############################################################
SET(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/Modules" ${CMAKE_MODULE_PATH})

#### boost
SET(Boost_USE_STATIC_LIBS ON)
FIND_PACKAGE(Boost REQUIRED)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})

#### libevent
FIND_PACKAGE(Libevent)
IF(Libevent_FOUND)
    INCLUDE_DIRECTORIES(${Libevent_INCLUDE_DIR})
    LINK_DIRECTORIES(${Libevent_LIBRARY_DIR})
ELSE()
    MESSAGE(FATAL_ERROR "Libevent not FOUND!")
ENDIF()

#### OpenSSL
FIND_PACKAGE(OpenSSL)
IF(OpenSSL_FOUND)
    INCLUDE_DIRECTORIES(${OpenSSL_INCLUDE_DIR})
    LINK_DIRECTORIES(${OpenSSL_LIBRARY_DIR})
ELSE()
    MESSAGE(FATAL_ERROR "OpenSSL not FOUND!")
ENDIF()

###############################################################################
INCLUDE_DIRECTORIES(
    ${PROJECT_SOURCE_DIR}
    ${PROJECT_SOURCE_DIR}/shared/
)
###############################################################################
ADD_SUBDIRECTORY(shared)